package com.reflect;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Properties;

public class ReflectD {
	public static void main(String[] args) throws FileNotFoundException,
			IOException {

		// RunTime

		// runnTime();

		Map<String, String> env = System.getenv();
		// 获取系统的所有环境变量
		for (String name : env.keySet()) {
			System.out.println(name + " : " + env.get(name));
		}
		// 获取系统的指定环境变量的值
		System.out.println(env.get("JAVA_HOME"));
		// 获取系统的所有属性
		Properties prop = System.getProperties();
		// 将系统的属性保存到配置文件中去
		prop.store(new FileOutputStream("Prop1.properties"),
				"System properties1");
		// 输出特定的系统属性
		System.out.println(System.getProperty("os.name"));

		// conversion();

		//
		// try {
		// reflectdemo();
		// } catch (ClassNotFoundException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }

	}

	private static void runnTime() {
		Runtime rt = Runtime.getRuntime();
		System.out.println(rt.freeMemory());
		System.out.println(rt.availableProcessors());
		System.out.println(rt.totalMemory());
		System.out.println(rt.maxMemory());
		System.out.println(rt.availableProcessors());

		try {
			rt.exec("notepad.exe");

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			rt.exec("cmd.exe");
			rt.exec("calc.exe");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("exception");
		}
	}

	private static void conversion() {
		int i10 = Integer.parseInt("a", 16);
		int i8 = Integer.parseInt("11", 8);
		String a16 = Integer.toHexString(10);

		System.out.println(i10);
		System.out.println(i8);
		System.out.println(a16);
	}

	@SuppressWarnings("unused")
	private static void reflectdemo() throws ClassNotFoundException {
		Class classType = Class.forName("java.io.InputStream");
		Method methods[] = classType.getDeclaredMethods();
		for (int i = 0; i < methods.length; i++) {
			System.out.println(methods[i].getName().toString());
		}
	}

}
